<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>客户资料信息查询</title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        var companyformSetting = {
            title: "客户资料管理",
            module: 'query',
            columns: [{
                name: "comInfoId",
                hidden: true
            }, {
                name: "name",
                label: "公司名称",
                type: "dropdown",
                dropdownType: "ajax",
                url: "../order-dropdown/getComName",
                op: "eq",
                minLength:2,
                keyWordName: "key",
                success: function (data) {
                    data = data.results;
                    var array = new Array();
                    $.each(data, function (i, n) {
                        array.push([n["text"], n["value"]]);
                    });
                    return array;
                }
            }, {
                name: "uniteCode",
                label: "统一社会信息代码",
            },
                {
                    name: "customsCode",
                    label: "海关注册代码"
                }, {
                    name: "status",
                    label: "审核状态",
                    type: "dropdown",
                    data: [["待审核", "0"], ["审核通过", "1"],["审核不通过", "2"],["草稿", "3"]]
                }, {
                    name: "ctimeStart",
                    label: "注册时间从",
                    type: "date",
                }, {
                    name: "ctimeEnd",
                    label: "注册时间至",
                    type: "date",
                }],
            buttons: {
                custom: [{
                    id: "selectbtn",
                    value: "新注册",
                    click: function () {
                        location.href = "/order/tacitCustomerRegistration";
                    }
                },
                    {
                        id: "selectbtn",
                        value: "修改",
                        click: function () {
                            var selectedRowId = $("#companyInfoDataGrid").getGridParam("selarrrow");
                            if (!selectedRowId || selectedRowId == "") {
                                jw.alert("请选择一条记录");
                            } else {
                                var selectedRow = $("#companyInfoDataGrid")
                                    .getRowData(selectedRowId);
                                location.href =
                                    "/order/tacitCustomerRegistration?comInfoId="
                                    + selectedRow.comInfoId;
                            }
                        }
                    }, {
                        id: "selectbtn",
                        value: "删除",
                        click: function () {
                            var selectedRowId = $("#companyInfoDataGrid")
                                .getGridParam("selrow");
                            if (selectedRowId) {
                                var selectedRow = $("#companyInfoDataGrid")
                                    .getRowData(selectedRowId);
                                if (confirm("确认要删除吗？")) {
                                    $.ajax({
                                               url: "./deleteCusInfo?comInfoId="
                                                    + selectedRow.comInfoId,
                                               dataType: "json",
                                               success: function (data) {
                                                   alert(data);
                                                   window.location.reload();
                                               }
                                           });
                                }
                            } else {
                                alert("请选择需要删除的记录!")
                            }
                        }
                    }
                ],
                formatter: $.jqGrid.custom.formatter.button
            },
            grid: {
                id: "companyInfoDataGrid",
                title: "查询结果",
                url: "findCusInfoDataList",
                dataType: "application/json",
                //data: ,
                multiselect: true,
                colModel: [{
                    index: "comInfoId",
                    name: "comInfoId",
                    hidden: true
                }, {
                    name: "name",
                    label: "公司名称"
                }, {
                    name: "uniteCode",
                    label: "统一社会信息代码"
                }, {
                    name: "customsCode",
                    label: "海关企业注册代码"
                }, {
                    name: "tGenComContact",
                    label: "联系人",
                    sortable: false,
                    buttons: [{
                        key: "attachmentDelBtn",
                        value: "查看联系人",
                        width: 120,
                        align: 'center',
                        click: function (gridid, rowId, rowdata) {
                            viewContracts(rowdata.agentRefId);
                        },
                        hide: function (rowdata) {
                            return rowdata.agentRefId === undefined;
                        }
                    }],
                    formatter: $.jqGrid.custom.formatter.button
                }, {
                    name: "creator",
                    label: "注册人"
                }, {
                    name: "agentRefId",
                    hidden: true
                }, {
                    name: "createTime",
                    label: "注册时间",
                }, {
                    name: "comValidate",
                    label: "审核状态",
                    formatter: function (val, opts, row) {
                        if (val === undefined || val === "null") {
                            return "草稿"
                        }
                        if ("0" === val) {
                            return "待审核"
                        } else if ("1" === val) {
                            return "审核通过"
                        } else if ("2" === val) {
                            return "审核不通过"
                        } else {
                            return val;
                        }
                    }
                },
                ]
            }
        };
        $(document).ready(function () {
            $("#companyInfoDataTable").mrdForm(companyformSetting);
        });


        function viewContracts(arefId) {
            layer.open({
                type: 2,
                title: false,
                content: "<s:url value='/tGenComContact/listPage'/>?agentRefId=" + arefId,
                area: ['840px', '400px']
            });
        }

    </script>
</head>
<body>
<div id="companyInfoDataTable"></div>
</body>
</html>
